package com.fjrcloud.controller;

import com.fjrcloud.service.UserService;
import com.fjrcloud.entity.ResponseBean;
import com.fjrcloud.entity.ResponseFactory;
import com.fjrcloud.entity.User;
import com.fjrcloud.exception.BusinessException;
import com.fjrcloud.utils.StatusUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by shengjian.lin on 17-2-11.
 */
@Controller
@RequestMapping("api/user")
public class UserController {

    @Autowired
    private UserService service;

    @RequestMapping("save")
    @ResponseBody
    public ResponseBean save(User user,Integer groupId) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.save(user,groupId));
    }
    @RequestMapping("change")
    @ResponseBody
    public ResponseBean change(Integer id,String old,String password) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.change(id,old,password));
    }
    @RequestMapping("get")
    @ResponseBody
    public ResponseBean get(Integer id){
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.get(id));
    }
    @RequestMapping("del")
    @ResponseBody
    public ResponseBean del(Integer id){
        service.del(id);
        return ResponseFactory.getResponseBean(StatusUtils.Success);
    }
    @RequestMapping("login")
    @ResponseBody
    public ResponseBean login(String username,String password) throws BusinessException {
        return ResponseFactory.getResponseBean(StatusUtils.Success,service.loginVerify(username,password));
    }
}
